home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / hc2_x / tcprogud.sit / TC Prog Guide / card_44454.txt < prev    next >
Text File  |  1991-02-27  |  2KB  |  37 lines

  1. -- card: 44454 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 4755
  5. -- name: 
  6.  
  7.  
  8. -- part contents for background part 6
  9. ----- text -----
  10. 5.1  Arithmetic Operators
  11.  
  12. -- part contents for background part 7
  13. ----- text -----
  14. 142
  15.  
  16. -- part contents for background part 4
  17. ----- text -----
  18. As expected, the multiplication '*' and division '/' operators have precedence over the addition '+' and subtraction '-' operators.  The modulus operator '%' produces the remainder when its integer operands divide each other.  No exponentiation operator is provided. The standard math library function pow() serves this purpose*.
  19.  
  20. One source of occasional programming errors is that arithmetic operations involving only integer values produce an integer result.  In the following example, the float variable f is initialized with the value 0 whereas g is assigned 0.5 (recall that constants must contain a decimal point to be considered as floating-point numbers).
  21.  
  22.     float  f = 1/2;          /* assigns 0 to f */
  23.     float  g = 1./2.;
  24.  
  25. The unary (one-operand) negation operator '-' has higher precedence than the foregoing operators, as do the unary increment '++' and decrement '--' operators.  These last operators are a shorthand for assigning the value of a variable incremented or decremented by 1 to the same variable.  As with other assignment operators, the change to the value of the variable is considered a "side effect", since
  26.  
  27. -- part contents for background part 29
  28. ----- text -----
  29. 34612
  30.  
  31. -- part contents for background part 27
  32. ----- text -----
  33. pow() function
  34.  
  35. -- part contents for background part 20
  36. ----- text -----
  37. pow() function - p193